#include <stdio.h>
int main(void)
{
    int high = 100;
    int low = 1;
    int guess = (100 - 1) / 2;
    char response;

    printf("选择一个从1到100的整数。我会尝试猜测它。\n");
    printf("用y表示猜对了，用h表示猜大了， 用l表示猜小了");
    printf("Uh...is your number %d?\n", guess);
    while ((response = getchar()) != 'y')
    {   
        if (response == 'h')
        {
            high = guess - 1;
            guess = (high - low) / 2;
            printf("Well, then, is it %d?\n", guess);
        }
        else if (response == 'l')
        {
            low = guess + 1;
            guess = (high - low) / 2;
            printf("Well, then, is it %d?\n", guess);
        }
        else
            printf("Sorry, 我不懂你的意思.\n");
        while (getchar() != '\n')   // 跳过剩余输入行，只看第一个
            continue;
    }
    printf("I knew I could do it!\n");

    return 0;
}